package com.hd.manager.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @projectName:    entrance_guard 
 * @package:        com.hd.manager.filter
 * @className:      WebFilter
 * @author:     otto
 * @description:  
 * @date:    2023/8/8 10:21
 * @version:    1.0
 */
@javax.servlet.annotation.WebFilter(filterName = "sessionFilter",urlPatterns = "/*")
@Order(1)
@Slf4j
public class WebFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req= (HttpServletRequest) servletRequest;
        req.getSession().setAttribute("ip",req.getRemoteHost());
        log.info("远程客户端ip: "+req.getRemoteHost());
        filterChain.doFilter(servletRequest,servletResponse);
    }
}

